/*
 * Copyright (C) 2008 The Android Open Source Project
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

/** @defgroup errno Errno
 * @ingroup libc
 */

#ifndef _ERRNO_H
#define _ERRNO_H

#include <sys/cdefs.h>
#ifndef __LITEOS__
#include <linux/errno.h>
#else
#include <liteos/errno.h>
#endif

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */


/* on Linux, ENOTSUP and EOPNOTSUPP are defined as the same error code
 * even if 1000.3 states that they should be different
 */
#ifndef  ENOTSUP
#define  ENOTSUP  EOPNOTSUPP
#endif

#ifdef __LITEOS__
/**
* @ingroup  errno
*
* @par Description:
* The set_errno() function sets the error code.
*
* @attention
* <ul>
* <li>The set_errno() function is not a standard C Library Function.</li>
* </ul>
*
* @retval #void None.
*
* @par Dependency:
* <ul><li>errno.h</li></ul>
* @see get_errno
* @since Huawei LiteOS V100R001C00
*/
extern void set_errno(int errcode);
/**
* @ingroup  errno
*
* @par Description:
* The get_errno() function gets the error code.
*
* @attention
* <ul>
* <li>The get_errno() function is not a standard C Library Function.</li>
* </ul>
*
* @retval #int The get_errno() returns the error code.
*
* @par Dependency:
* <ul><li>errno.h</li></ul>
* @see set_errno
* @since Huawei LiteOS V100R001C00
*/
extern int get_errno(void);
#endif

/* internal function returning the address of the thread-specific errno */
extern volatile int* __errno(void) __pure2;

/* a macro expanding to the errno l-value */
#define  errno   (*__errno())

#ifndef __LITEOS__
#if __ANDROID_API__ < 21
#include <android/legacy_errno_inlines.h>
#endif
#endif


#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

#endif /* _ERRNO_H */
